
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>UIKit · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="WebView.html" />
    
    
    <link rel="prev" href="Foundation.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    关于
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Part I</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="Data-structure.html">
            
                <a href="Data-structure.html">
            
                    
                    数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="Arithmetic.html">
            
                <a href="Arithmetic.html">
            
                    
                    算法
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Part II</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="Foundation.html">
            
                <a href="Foundation.html">
            
                    
                    Foundation
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.2" data-path="UIKit.html">
            
                <a href="UIKit.html">
            
                    
                    UIKit
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="WebView.html">
            
                <a href="WebView.html">
            
                    
                    WebView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="Memory-management.html">
            
                <a href="Memory-management.html">
            
                    
                    内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="Message-passing.html">
            
                <a href="Message-passing.html">
            
                    
                    消息传递的方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="Network.html">
            
                <a href="Network.html">
            
                    
                    网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="Data-storage.html">
            
                <a href="Data-storage.html">
            
                    
                    数据存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="Multi-thread.html">
            
                <a href="Multi-thread.html">
            
                    
                    多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="Animation.html">
            
                <a href="Animation.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="Image-processing.html">
            
                <a href="Image-processing.html">
            
                    
                    图像处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="Data-encryption.html">
            
                <a href="Data-encryption.html">
            
                    
                    数据安全及加密
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="Runtime.html">
            
                <a href="Runtime.html">
            
                    
                    Runtime
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="Runloop.html">
            
                <a href="Runloop.html">
            
                    
                    Runloop
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Part III</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="Project-organization.html">
            
                <a href="Project-organization.html">
            
                    
                    项目架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="Design-patterns.html">
            
                <a href="Design-patterns.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="Component-based.html">
            
                <a href="Component-based.html">
            
                    
                    组件化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Debug-tips.html">
            
                <a href="Debug-tips.html">
            
                    
                    调试技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="Performance-optimization.html">
            
                <a href="Performance-optimization.html">
            
                    
                    性能优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="Source-code.html">
            
                <a href="Source-code.html">
            
                    
                    源码理解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="Code-management.html">
            
                <a href="Code-management.html">
            
                    
                    代码管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="Continuous-integration.html">
            
                <a href="Continuous-integration.html">
            
                    
                    持续集成
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >UIKit</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="uikit">UIKit</h1>
<h2 id="1uiview-&#x548C;-calayer-&#x662F;&#x4EC0;&#x4E48;&#x5173;&#x7CFB;&#xFF1F;">1.UIView &#x548C; CALayer &#x662F;&#x4EC0;&#x4E48;&#x5173;&#x7CFB;&#xFF1F;</h2>
<ul>
<li><p>UIView &#x7EE7;&#x627F; UIResponder&#xFF0C;&#x800C; UIResponder &#x662F;&#x54CD;&#x5E94;&#x8005;&#x5BF9;&#x8C61;&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;iOS &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x54CD;&#x5E94;&#x53CA;&#x4F20;&#x9012;&#xFF0C;CALayer &#x6CA1;&#x6709;&#x7EE7;&#x627F;&#x81EA; UIResponder&#xFF0C;&#x6240;&#x4EE5; CALayer &#x4E0D;&#x5177;&#x5907;&#x54CD;&#x5E94;&#x5904;&#x7406;&#x4E8B;&#x4EF6;&#x7684;&#x80FD;&#x529B;&#x3002;CALayer &#x662F; QuartzCore &#x4E2D;&#x7684;&#x7C7B;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x5E95;&#x5C42;&#x7684;&#x7528;&#x6765;&#x7ED8;&#x5236;&#x5185;&#x5BB9;&#x7684;&#x7C7B;&#xFF0C;&#x7528;&#x6765;&#x7ED8;&#x5236;UI</p>
</li>
<li><p>UIView &#x5BF9; CALayer &#x5C01;&#x88C5;&#x5C5E;&#x6027;&#xFF0C;&#x5BF9; UIView &#x8BBE;&#x7F6E; frame&#x3001;center&#x3001;bounds &#x7B49;&#x4F4D;&#x7F6E;&#x4FE1;&#x606F;&#x65F6;&#xFF0C;&#x5176;&#x5B9E;&#x90FD;&#x662F;UIView &#x5BF9; CALayer &#x8FDB;&#x4E00;&#x5C42;&#x5C01;&#x88C5;&#xFF0C;&#x4F7F;&#x5F97;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5F88;&#x65B9;&#x4FBF;&#x5730;&#x8BBE;&#x7F6E;&#x63A7;&#x4EF6;&#x7684;&#x4F4D;&#x7F6E;&#xFF1B;&#x4F8B;&#x5982;&#x5706;&#x89D2;&#x3001;&#x9634;&#x5F71;&#x7B49;&#x5C5E;&#x6027;&#xFF0C; UIView &#x5C31;&#x6CA1;&#x6709;&#x8FDB;&#x4E00;&#x6B65;&#x5C01;&#x88C5;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x8FD8;&#x662F;&#x9700;&#x8981;&#x53BB;&#x8BBE;&#x7F6E; Layer &#x7684;&#x5C5E;&#x6027;&#x6765;&#x5B9E;&#x73B0;&#x529F;&#x80FD;&#x3002;</p>
</li>
<li><p>UIView &#x662F; CALayer &#x7684;&#x4EE3;&#x7406;&#xFF0C;UIView &#x6301;&#x6709;&#x4E00;&#x4E2A; CALayer &#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x5E76;&#x4E14;&#x662F;&#x8BE5;&#x5C5E;&#x6027;&#x7684;&#x4EE3;&#x7406;&#xFF0C;&#x7528;&#x6765;&#x63D0;&#x4F9B;&#x4E00;&#x4E9B; CALayer &#x884C;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x4F8B;&#x5982;&#x52A8;&#x753B;&#x548C;&#x7ED8;&#x5236;&#x3002;</p>
</li>
</ul>
<h2 id="2bounds-&#x548C;-frame-&#x7684;&#x533A;&#x522B;">2.Bounds &#x548C; Frame &#x7684;&#x533A;&#x522B;?</h2>
<ul>
<li><p>Bounds&#xFF1A;&#x4E00;&#x822C;&#x662F;&#x76F8;&#x5BF9;&#x4E8E;&#x81EA;&#x8EAB;&#x6765;&#x8BF4;&#x7684;&#xFF0C;&#x662F;&#x63A7;&#x4EF6;&#x7684;&#x5185;&#x90E8;&#x5C3A;&#x5BF8;&#x3002;&#x5982;&#x679C;&#x4F60;&#x4FEE;&#x6539;&#x4E86; Bounds&#xFF0C;&#x90A3;&#x4E48;&#x5B50;&#x63A7;&#x4EF6;&#x7684;&#x76F8;&#x5BF9;&#x4F4D;&#x7F6E;&#x4E5F;&#x4F1A;&#x53D1;&#x751F;&#x6539;&#x53D8;&#x3002;</p>
</li>
<li><p>Frame &#xFF1A;&#x662F;&#x76F8;&#x5BF9;&#x4E8E;&#x7236;&#x63A7;&#x4EF6;&#x6765;&#x8BF4;&#x7684;&#xFF0C;&#x662F;&#x63A7;&#x4EF6;&#x7684;&#x5916;&#x90E8;&#x5C3A;&#x5BF8;&#x3002;</p>
</li>
</ul>
<h2 id="3setneedsdisplay-&#x548C;-layoutifneeded-&#x4E24;&#x8005;&#x662F;&#x4EC0;&#x4E48;&#x5173;&#x7CFB;&#xFF1F;">3.setNeedsDisplay &#x548C; layoutIfNeeded &#x4E24;&#x8005;&#x662F;&#x4EC0;&#x4E48;&#x5173;&#x7CFB;&#xFF1F;</h2>
<p>UIView&#x7684;setNeedsDisplay&#x548C;setNeedsLayout&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x90FD;&#x662F;&#x5F02;&#x6B65;&#x6267;&#x884C;&#x7684;&#x3002;&#x800C;setNeedsDisplay&#x4F1A;&#x81EA;&#x52A8;&#x8C03;&#x7528;drawRect&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x62FF;&#x5230;UIGraphicsGetCurrentContext&#x8FDB;&#x884C;&#x7ED8;&#x5236;&#xFF1B;&#x800C;setNeedsLayout&#x4F1A;&#x9ED8;&#x8BA4;&#x8C03;&#x7528;layoutSubViews&#xFF0C;&#x7ED9;&#x5F53;&#x524D;&#x7684;&#x89C6;&#x56FE;&#x505A;&#x4E86;&#x6807;&#x8BB0;&#xFF1B;layoutIfNeeded &#x67E5;&#x627E;&#x662F;&#x5426;&#x6709;&#x6807;&#x8BB0;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x6807;&#x8BB0;&#x53CA;&#x7ACB;&#x523B;&#x5237;&#x65B0;&#x3002;</p>
<p>&#x53EA;&#x6709;setNeedsLayout&#x548C;layoutIfNeeded&#x8FD9;&#x4E8C;&#x8005;&#x5408;&#x8D77;&#x6765;&#x4F7F;&#x7528;&#xFF0C;&#x624D;&#x4F1A;&#x8D77;&#x5230;&#x7ACB;&#x523B;&#x5237;&#x65B0;&#x7684;&#x6548;&#x679C;&#x3002;</p>
<h2 id="4&#x8C08;&#x8C08;&#x5BF9;uiresponder&#x7684;&#x7406;&#x89E3;">4.&#x8C08;&#x8C08;&#x5BF9;UIResponder&#x7684;&#x7406;&#x89E3;</h2>
<p>UIResponder&#x7C7B;&#x662F;&#x4E13;&#x95E8;&#x7528;&#x6765;&#x54CD;&#x5E94;&#x7528;&#x6237;&#x7684;&#x64CD;&#x4F5C;&#x5904;&#x7406;&#x5404;&#x79CD;&#x4E8B;&#x4EF6;&#x7684;&#xFF0C;&#x5305;&#x62EC;&#x89E6;&#x6478;&#x4E8B;&#x4EF6;(Touch Events)&#x3001;&#x8FD0;&#x52A8;&#x4E8B;&#x4EF6;(Motion Events)&#x3001;&#x8FDC;&#x7A0B;&#x63A7;&#x5236;&#x4E8B;&#x4EF6;(Remote Control Events)&#x3002;&#x6211;&#x4EEC;&#x77E5;&#x9053;UIApplication&#x3001;UIView&#x3001;UIViewController&#x8FD9;&#x51E0;&#x4E2A;&#x7C7B;&#x662F;&#x76F4;&#x63A5;&#x7EE7;&#x627F;&#x81EA;UIResponder&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x4E9B;&#x7C7B;&#x90FD;&#x53EF;&#x4EE5;&#x54CD;&#x5E94;&#x4E8B;&#x4EF6;&#x3002;&#x5F53;&#x7136;&#x6211;&#x4EEC;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x7EE7;&#x627F;&#x81EA;UIView&#x7684;View&#x4EE5;&#x53CA;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x7EE7;&#x627F;&#x81EA;UIViewController&#x7684;&#x63A7;&#x5236;&#x5668;&#x90FD;&#x53EF;&#x4EE5;&#x54CD;&#x5E94;&#x4E8B;&#x4EF6;&#x3002;</p>
<h2 id="5loadview&#x7684;&#x4F5C;&#x7528;&#xFF1F;">5.loadView&#x7684;&#x4F5C;&#x7528;&#xFF1F;</h2>
<p>loadView&#x65B9;&#x6CD5;&#x4F1A;&#x5728;&#x6BCF;&#x6B21;&#x8BBF;&#x95EE;UIViewController&#x7684;view(&#x6BD4;&#x5982;controller.view&#x3001;self.view)&#x800C;&#x4E14;view&#x4E3A;nil&#x65F6;&#x4F1A;&#x88AB;&#x8C03;&#x7528;&#xFF0C;&#x6B64;&#x65B9;&#x6CD5;&#x4E3B;&#x8981;&#x7528;&#x6765;&#x8D1F;&#x8D23;&#x521B;&#x5EFA;UIViewController&#x7684;view(&#x91CD;&#x5199;loadView&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x4E14;&#x4E0D;&#x9700;&#x8981;&#x8C03;&#x7528;[super loadView])</p>
<p>&#x8FD9;&#x91CC;&#x8981;&#x63D0;&#x4E00;&#x4E0B; [super loadView]&#xFF0C;[super loadView]&#x505A;&#x4E86;&#x4E0B;&#x9762;&#x51E0;&#x4EF6;&#x4E8B;&#x3002;</p>
<ul>
<li><p>&#x5B83;&#x4F1A;&#x5148;&#x53BB;&#x67E5;&#x627E;&#x4E0E;UIViewController&#x76F8;&#x5173;&#x8054;&#x7684;xib&#x6587;&#x4EF6;&#xFF0C;&#x901A;&#x8FC7;&#x52A0;&#x8F7D;xib&#x6587;&#x4EF6;&#x6765;&#x521B;&#x5EFA;UIViewController&#x7684;view&#xFF0C;&#x5982;&#x679C;&#x5728;&#x521D;&#x59CB;&#x5316;UIViewController&#x6307;&#x5B9A;&#x4E86;xib&#x6587;&#x4EF6;&#x540D;&#xFF0C;&#x5C31;&#x4F1A;&#x6839;&#x636E;&#x4F20;&#x5165;&#x7684;xib&#x6587;&#x4EF6;&#x540D;&#x52A0;&#x8F7D;&#x5BF9;&#x5E94;&#x7684;xib&#x6587;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x660E;&#x663E;&#x5730;&#x4F20;xib&#x6587;&#x4EF6;&#x540D;&#xFF0C;&#x5C31;&#x4F1A;&#x52A0;&#x8F7D;&#x8DDF;UIViewController&#x540C;&#x540D;&#x7684;xib&#x6587;&#x4EF6;</p>
</li>
<li><p>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#x76F8;&#x5173;&#x8054;&#x7684;xib&#x6587;&#x4EF6;&#xFF0C;&#x5C31;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x767D;&#x7684;UIView&#xFF0C;&#x7136;&#x540E;&#x8D4B;&#x503C;&#x7ED9;UIViewController&#x7684;view&#x5C5E;&#x6027;</p>
</li>
</ul>
<p>&#x7EFC;&#x4E0A;&#xFF0C;&#x5728;&#x9700;&#x8981;&#x81EA;&#x5B9A;&#x4E49;UIViewController&#x7684;view&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x91CD;&#x5199;loadView&#x65B9;&#x6CD5;&#x4E14;&#x4E0D;&#x9700;&#x8981;&#x8C03;&#x7528;[super loadView]&#x65B9;&#x6CD5;&#x3002;</p>
<h2 id="6&#x4F7F;&#x7528;-drawrect&#x6709;&#x4EC0;&#x4E48;&#x5F71;&#x54CD;&#xFF1F;">6.&#x4F7F;&#x7528; drawRect&#x6709;&#x4EC0;&#x4E48;&#x5F71;&#x54CD;&#xFF1F;</h2>
<p>drawRect &#x65B9;&#x6CD5;&#x4F9D;&#x8D56; Core Graphics &#x6846;&#x67B6;&#x6765;&#x8FDB;&#x884C;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x7ED8;&#x5236;
&#x7F3A;&#x70B9;&#xFF1A;&#x5B83;&#x5904;&#x7406; touch &#x4E8B;&#x4EF6;&#x65F6;&#x6BCF;&#x6B21;&#x6309;&#x94AE;&#x88AB;&#x70B9;&#x51FB;&#x540E;&#xFF0C;&#x90FD;&#x4F1A;&#x7528; setNeddsDisplay &#x8FDB;&#x884C;&#x5F3A;&#x5236;&#x91CD;&#x7ED8;&#xFF1B;&#x800C;&#x4E14;&#x4E0D;&#x6B62;&#x4E00;&#x6B21;&#xFF0C;&#x6BCF;&#x6B21;&#x5355;&#x70B9;&#x4E8B;&#x4EF6;&#x89E6;&#x53D1;&#x4E24;&#x6B21;&#x6267;&#x884C;&#x3002;&#x8FD9;&#x6837;&#x7684;&#x8BDD;&#x4ECE;&#x6027;&#x80FD;&#x7684;&#x89D2;&#x5EA6;&#x6765;&#x8BF4;&#xFF0C;&#x5BF9; CPU &#x548C;&#x5185;&#x5B58;&#x6765;&#x8BF4;&#x90FD;&#x662F;&#x6B20;&#x4F73;&#x7684;&#x3002;&#x7279;&#x522B;&#x662F;&#x5982;&#x679C;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x754C;&#x9762;&#x4E0A;&#x6709;&#x591A;&#x4E2A;&#x8FD9;&#x6837;&#x7684;UIButton &#x5B9E;&#x4F8B;&#xFF0C;&#x90A3;&#x5C31;&#x4F1A;&#x5F88;&#x7CDF;&#x7CD5;&#x4E86;&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x8C03;&#x7528;&#x673A;&#x5236;&#x4E5F;&#x662F;&#x975E;&#x5E38;&#x7279;&#x522B;. &#x5F53;&#x4F60;&#x8C03;&#x7528; setNeedsDisplay &#x65B9;&#x6CD5;&#x65F6;, UIKit &#x5C06;&#x4F1A;&#x628A;&#x5F53;&#x524D;&#x56FE;&#x5C42;&#x6807;&#x8BB0;&#x4E3A; dirty,&#x4F46;&#x8FD8;&#x662F;&#x4F1A;&#x663E;&#x793A;&#x539F;&#x6765;&#x7684;&#x5185;&#x5BB9;,&#x76F4;&#x5230;&#x4E0B;&#x4E00;&#x6B21;&#x7684;&#x89C6;&#x56FE;&#x6E32;&#x67D3;&#x5468;&#x671F;,&#x624D;&#x4F1A;&#x5C06;&#x6807;&#x8BB0;&#x4E3A; dirty &#x7684;&#x56FE;&#x5C42;&#x91CD;&#x65B0;&#x5EFA;&#x7ACB; Core Graphics &#x4E0A;&#x4E0B;&#x6587;,&#x7136;&#x540E;&#x5C06;&#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x6062;&#x590D;&#x51FA;&#x6765;, &#x518D;&#x4F7F;&#x7528; CGContextRef &#x8FDB;&#x884C;&#x7ED8;&#x5236;</p>
<h2 id="7keywindow-&#x548C;-delegate&#x7684;window&#x6709;&#x4F55;&#x533A;&#x522B;">7.keyWindow &#x548C; delegate&#x7684;window&#x6709;&#x4F55;&#x533A;&#x522B;</h2>
<ul>
<li><p>delegate.window &#x7A0B;&#x5E8F;&#x542F;&#x52A8;&#x65F6;&#x8BBE;&#x7F6E;&#x7684;window&#x5BF9;&#x8C61;&#x3002;</p>
</li>
<li><p>keyWindow &#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x4FDD;&#x5B58;&#x4E86;[windows]&#x6570;&#x7EC4;&#x4E2D;&#x7684;[UIWindow]&#x5BF9;&#x8C61;&#xFF0C;&#x8BE5;&#x5BF9;&#x8C61;&#x6700;&#x8FD1;&#x88AB;&#x53D1;&#x9001;&#x4E86;[makeKeyAndVisible]&#x6D88;&#x606F;</p>
</li>
</ul>
<p>&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x4E0B; delegate.window &#x548C; keyWindow &#x662F;&#x540C;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x4F46;&#x4E0D;&#x80FD;&#x4FDD;&#x8BC1;keyWindow&#x5C31;&#x662F;delegate.window&#xFF0C;&#x56E0;&#x4E3A;keyWindow&#x4F1A;&#x56E0;&#x4E3A;makeKeyAndVisible&#x800C;&#x53D8;&#x5316;&#xFF0C;&#x4F8B;&#x5982;&#xFF0C;&#x7A0B;&#x5E8F;&#x4E2D;&#x6DFB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x60AC;&#x6D6E;&#x7A97;&#x53E3;&#xFF0C;&#x8FD9;&#x4E2A;&#x65F6;&#x5019;keywindow&#x5C31;&#x4F1A;&#x53D8;&#x5316;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Foundation.html" class="navigation navigation-prev " aria-label="Previous page: Foundation">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="WebView.html" class="navigation navigation-next " aria-label="Next page: WebView">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"UIKit","level":"3.2","depth":1,"next":{"title":"WebView","level":"3.3","depth":1,"path":"WebView.md","ref":"WebView.md","articles":[]},"previous":{"title":"Foundation","level":"3.1","depth":1,"path":"Foundation.md","ref":"Foundation.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"UIKit.md","mtime":"2020-04-13T10:23:32.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-05-27T09:12:21.691Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

